using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Forms;
using System.Windows.Markup;
using Common;
using Common.Enum;
using Converters;
using Infragistics.Win;
using Infragistics.Win.UltraWinDataSource;
using Infragistics.Win.UltraWinGrid;
using SExperiment;
using SExperiment.ExperimentResult;
using SProject.Paramter;
using SSettings;

namespace SettingsView.Search
{
	public partial class UCSearchWellInfo : System.Windows.Controls.UserControl, IComponentConnector
	{
		public const string Key_SearchResult_ExperimentName = "Search.Result.ExperimentName";

		public const string Key_SearchResult_ExperimentDate = "Search.Result.ExperimentDate";

		public const string Key_SearchResult_SampleName = "Search.Result.SampleName";

		public const string Key_SearchResult_FileName = "Search.Result.FileName";

		public const string Key_MidValueTarget = "SampleTargetItem.Result.MidValue";

		public const string Key_MidValueWell = "WellCell.Well.Result.MidValue";

		public const string Key_MidValueSample = "WellCell.Well.Sample.Result.MidValue";

		private const int CellPadding = 2;

		private bool _UseScientific = true;

		private GridColumns _GridColumns;

		public UltraGrid ultraGrid = new UltraGrid();

		private UltraDataSource informationTable = new UltraDataSource();

		private NumberFormatInfo numberFormatInfo;

		public static readonly RoutedEvent OnSearchExperimentOpenChangedRoutedEvent = EventManager.RegisterRoutedEvent("OnSearchExperimentOpenChangedRoutedEvent", RoutingStrategy.Bubble, typeof(EventHandler<RoutedEventArgs>), typeof(UCSearchWellInfo));

		private ObservableCollection<SearchData> _SearchDatas = new ObservableCollection<SearchData>();

		private System.Windows.Controls.ContextMenu contextMenu = new System.Windows.Controls.ContextMenu();

		public bool UseScientific
		{
			get
			{
				return _UseScientific;
			}
			set
			{
				_UseScientific = value;
			}
		}

		public GridColumns GridColumns
		{
			get
			{
				return _GridColumns;
			}
			set
			{
				_GridColumns = value;
			}
		}

		public ObservableCollection<SearchData> SearchDatas
		{
			get
			{
				return _SearchDatas;
			}
			set
			{
				if (_SearchDatas != value)
				{
					_SearchDatas = value;
				}
			}
		}

		public event RoutedEventHandler OnSearchExperimentOpenChanged
		{
			add
			{
				AddHandler(OnSearchExperimentOpenChangedRoutedEvent, value);
			}
			remove
			{
				RemoveHandler(OnSearchExperimentOpenChangedRoutedEvent, value);
			}
		}

		private void RaiseExperimentStatusChanged()
		{
			RaiseEvent(new RoutedEventArgs
			{
				RoutedEvent = OnSearchExperimentOpenChangedRoutedEvent
			});
		}

		public UCSearchWellInfo()
		{
			InitializeComponent();
			InitUltraGrid();
		}

		public void Refresh()
		{
			UseScientific = ConfigSettings.GetInstance().ExperimentSetting.UseScientific;
			RefreshColumns();
			informationTable.Rows.SetCount((SearchDatas != null) ? SearchDatas.Count : 0);
			ultraGrid.Rows.Refresh(RefreshRow.ReloadData);
			int num = ((SearchDatas != null) ? SearchDatas.Count : 0);
			ultraGrid.DisplayLayout.Override.RowSelectorWidth = ((num <= 999) ? 30 : (num.ToString().Length * 10));
		}

		private void AutoSizeColumnSize()
		{
			Graphics graphics = ultraGrid.CreateGraphics();
			foreach (UltraGridColumn column in ultraGrid.DisplayLayout.Bands[0].Columns)
			{
				string caption = column.Header.Caption;
				caption += "WW";
				if (ultraGrid.DisplayLayout.Bands[0].SortedColumns.Contains(column))
				{
					caption += "WW";
				}
				string text = string.Empty;
				if (column.Key == "SampleTargetItem.LineColor")
				{
					text = "WWW";
				}
				else
				{
					foreach (UltraGridRow item in ultraGrid.Rows.Where((UltraGridRow s) => !s.IsFilteredOut).ToList())
					{
						object columnData = GetColumnData(column.Key, SearchDatas[item.ListIndex], column.Key == "SampleTargetItem.Result.CnValue");
						string text2 = ((columnData == null) ? null : columnData.ToString());
						if (!string.IsNullOrEmpty(text2) && text.Length < text2.Length)
						{
							text = text2;
						}
					}
				}
				int num = (int)graphics.MeasureString(caption, ultraGrid.Font).Width;
				int num2 = (int)graphics.MeasureString(text, ultraGrid.Font).Width + 4 + 4;
				column.Width = ((num > num2) ? num : num2);
			}
			graphics.Dispose();
		}

		public void RefreshColumns()
		{
			if (GridColumns == null)
			{
				return;
			}
			informationTable.Band.Columns.Clear();
			int num = 0;
			foreach (ColumnInfo column in GridColumns.Columns)
			{
				if (column.IsCustomColumn() || string.IsNullOrEmpty(column.FieldName))
				{
					continue;
				}
				if (column.FieldName == "SampleTargetItem.Result.Tm")
				{
					int tmCount = GetTmCount();
					List<UltraDataColumn> list = (from UltraDataColumn s in informationTable.Band.Columns
						where s.Key.IndexOf("SampleTargetItem.Result.Tm") == 0 || s.Key.IndexOf("SampleTargetItem.Result.Rm") == 0
						select s).ToList();
					foreach (UltraDataColumn item in list)
					{
						string text = item.Key.ToString();
						if (text.IndexOf("SampleTargetItem.Result.Tm") == 0)
						{
							text = text.Replace("SampleTargetItem.Result.Tm", string.Empty);
							if (int.Parse(text) >= tmCount)
							{
								informationTable.Band.Columns.Remove(item);
							}
						}
						else if (text.IndexOf("SampleTargetItem.Result.Rm") == 0)
						{
							text = text.Replace("SampleTargetItem.Result.Rm", string.Empty);
							if (int.Parse(text) >= tmCount)
							{
								informationTable.Band.Columns.Remove(item);
							}
						}
					}
					ColumnInfo columnInfo = GridColumns.Columns.Where((ColumnInfo s) => s.FieldName == "SampleTargetItem.Result.Rm").FirstOrDefault();
					for (int i = 0; i < tmCount; i++)
					{
						InsertNewColumn("SampleTargetItem.Result.Tm" + i, num++, column.Header + (i + 1), column.Visibility);
						InsertNewColumn("SampleTargetItem.Result.Rm" + i, num++, columnInfo.Header + (i + 1), columnInfo.Visibility);
					}
				}
				else
				{
					if (column.FieldName == "SampleTargetItem.Result.Rm")
					{
						continue;
					}
					if (column.FieldName == "SampleTargetItem.Result.MidValue")
					{
						List<UltraDataColumn> list = (from UltraDataColumn s in informationTable.Band.Columns
							where s.Key.IndexOf("SampleTargetItem.Result.MidValue") == 0 || s.Key.IndexOf("WellCell.Well.Result.MidValue") == 0 || s.Key.IndexOf("WellCell.Well.Sample.Result.MidValue") == 0
							select s).ToList();
						List<KeyValuePair> midValue = GetMidValue();
						foreach (UltraDataColumn item2 in list)
						{
							if (!IsExist(midValue, item2.Key))
							{
								informationTable.Band.Columns.Remove(item2);
							}
						}
						foreach (KeyValuePair item3 in midValue)
						{
							InsertNewColumn(item3.Key.ToString(), num++, item3.Value.ToString(), column.Visibility);
						}
					}
					else if (column.FieldName == "SampleTargetItem.Result.ConclusionList")
					{
						InsertNewColumn("WellCell.Well.Sample.Result.ConclusionList".ToString(), num++, Utility.GetMessage("Prj_SampleConclusion"), column.Visibility);
						InsertNewColumn("WellCell.Well.Result.ConclusionList".ToString(), num++, Utility.GetMessage("Prj_WellConclusion"), column.Visibility);
						InsertNewColumn("SampleTargetItem.Result.ConclusionList".ToString(), num++, Utility.GetMessage("Prj_TargetConclusion"), column.Visibility);
					}
					else
					{
						InsertNewColumn(column.FieldName, num++, column.Header, column.Visibility);
					}
				}
			}
		}

		private bool IsExist(List<KeyValuePair> list, string key)
		{
			return list.Where((KeyValuePair s) => s.Key.ToString() == key).Count() > 0;
		}

		private int GetTmCount()
		{
			int result = 0;
			if (SearchDatas == null)
			{
				return result;
			}
			if (SearchDatas.Count > 0 && SearchDatas[0].Item.Result is MeltingTargetResult)
			{
				IEnumerable<SearchData> searchDatas = SearchDatas;
				List<int> list = searchDatas.Select((SearchData s) => ((MeltingTargetResult)s.Item.Result).PeakValues.Count).ToList();
				result = ((list.Count > 0) ? list.Max() : 0);
			}
			return result;
		}

		private List<KeyValuePair> GetMidValue()
		{
			List<KeyValuePair> list = new List<KeyValuePair>();
			if (SearchDatas == null)
			{
				return list;
			}
			IEnumerable<SearchData> searchDatas = SearchDatas;
			foreach (SearchData item in searchDatas)
			{
				foreach (MidValue midValue in item.Well.Sample.Result.MidValues)
				{
					string key = "WellCell.Well.Sample.Result.MidValue" + midValue.Name;
					if (!IsExist(list, key))
					{
						list.Add(new KeyValuePair
						{
							Key = key,
							Value = midValue.Name
						});
					}
				}
				foreach (MidValue midValue2 in item.Well.Result.MidValues)
				{
					string key = "WellCell.Well.Result.MidValue" + midValue2.Name;
					if (!IsExist(list, key))
					{
						list.Add(new KeyValuePair
						{
							Key = key,
							Value = midValue2.Name
						});
					}
				}
				foreach (MidValue midValue3 in item.Item.Result.MidValues)
				{
					string key = "SampleTargetItem.Result.MidValue" + midValue3.Name;
					if (!IsExist(list, key))
					{
						list.Add(new KeyValuePair
						{
							Key = key,
							Value = midValue3.Name
						});
					}
				}
			}
			return list;
		}

		private void InsertNewColumn(string key, int index, string header, bool visible)
		{
			UltraGridColumn ultraGridColumn = (from UltraGridColumn s in ultraGrid.DisplayLayout.Bands[0].Columns
				where s.Key == key
				select s).FirstOrDefault();
			if (ultraGridColumn == null)
			{
				if (key == "SampleTargetItem.ChannelNo")
				{
					informationTable.Band.Columns.Add(key, typeof(int));
				}
				else if (IsDisplayNumberKey(key))
				{
					informationTable.Band.Columns.Add(key, typeof(double));
				}
				else
				{
					informationTable.Band.Columns.Add(key, typeof(string));
				}
				ultraGridColumn = (from UltraGridColumn s in ultraGrid.DisplayLayout.Bands[0].Columns
					where s.Key == key
					select s).FirstOrDefault();
				ultraGridColumn.FilterClearButtonVisible = DefaultableBoolean.False;
				ultraGridColumn.MergedCellStyle = MergedCellStyle.Never;
				ultraGridColumn.AllowRowFiltering = DefaultableBoolean.False;
				ultraGridColumn.Width = 60;
				string caption = header;
				if (key.IndexOf("SampleTargetItem.Result.Tm") == 0)
				{
					ultraGridColumn.Format = "#,0.00";
					ultraGridColumn.FormatInfo = numberFormatInfo;
				}
				else if (key.IndexOf("SampleTargetItem.Result.Rm") == 0)
				{
					ultraGridColumn.Format = "#,0.00";
					ultraGridColumn.FormatInfo = numberFormatInfo;
				}
				else if (key.IndexOf("SampleTargetItem.Result.MidValue") == 0)
				{
					caption = key.Replace("SampleTargetItem.Result.MidValue", "");
				}
				else if (key.IndexOf("WellCell.Well.Result.MidValue") == 0)
				{
					caption = key.Replace("WellCell.Well.Result.MidValue", "");
				}
				else if (key.IndexOf("WellCell.Well.Sample.Result.MidValue") == 0)
				{
					caption = key.Replace("WellCell.Well.Sample.Result.MidValue", "");
				}
				else
				{
					switch (key)
					{
					case "WellCell.Well.CellName":
						ultraGridColumn.Width = 60;
						break;
					case "WellCell.Well.TubeName":
						ultraGridColumn.Width = 80;
						break;
					case "SampleTargetItem.ChannelNo":
					case "WellCell.Well.Project.BasicInfo.Name":
						ultraGridColumn.Width = 60;
						break;
					case "SampleTargetItem.Dye":
					case "SampleTargetItem.TargetName":
						ultraGridColumn.Width = 50;
						break;
					case "SampleTargetItem.LineColor":
						ultraGridColumn.AllowRowFiltering = DefaultableBoolean.False;
						ultraGridColumn.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.FormattedText;
						ultraGridColumn.Width = 50;
						break;
					case "SampleTargetItem.SampleType":
						ultraGridColumn.Width = 70;
						break;
					case "SampleTargetItem.Property":
						ultraGridColumn.Width = 70;
						break;
					case "WellCell.Well.Sample.CompoundTubeNo":
						ultraGridColumn.Width = 50;
						break;
					case "SampleTargetItem.Result.CtValue":
						ultraGridColumn.Format = "#,0.00";
						ultraGridColumn.FormatInfo = numberFormatInfo;
						ultraGridColumn.Width = 60;
						break;
					case "SampleTargetItem.Result.CtMean":
						ultraGridColumn.Format = "#,0.00";
						ultraGridColumn.FormatInfo = numberFormatInfo;
						ultraGridColumn.Width = 80;
						break;
					case "SampleTargetItem.Result.CtSD":
						ultraGridColumn.Format = "#,0.00";
						ultraGridColumn.FormatInfo = numberFormatInfo;
						ultraGridColumn.Width = 80;
						break;
					case "SampleTargetItem.Result.CtCV":
						ultraGridColumn.Format = "#,0.00";
						ultraGridColumn.FormatInfo = numberFormatInfo;
						ultraGridColumn.Width = 80;
						break;
					case "SampleTargetItem.Result.CnValue":
						ultraGridColumn.SortComparer = new CustomCnValueComparer();
						ultraGridColumn.RowFilterComparer = new CustomCnValueComparer();
						ultraGridColumn.Width = 100;
						break;
					case "SampleTargetItem.Result.CnMean":
						ultraGridColumn.Format = (UseScientific ? "0.000E0" : "#,0.00");
						ultraGridColumn.FormatInfo = numberFormatInfo;
						ultraGridColumn.Width = 80;
						break;
					case "SampleTargetItem.Result.CnSD":
						ultraGridColumn.Format = (UseScientific ? "0.000E0" : "#,0.00");
						ultraGridColumn.FormatInfo = numberFormatInfo;
						ultraGridColumn.Width = 80;
						break;
					case "SampleTargetItem.Result.CnCV":
						ultraGridColumn.Format = "#,0.00";
						ultraGridColumn.FormatInfo = numberFormatInfo;
						ultraGridColumn.Width = 80;
						break;
					case "SampleTargetItem.Result.RnValue":
						ultraGridColumn.Format = "#,0.000";
						ultraGridColumn.FormatInfo = numberFormatInfo;
						ultraGridColumn.Width = 80;
						break;
					case "SampleTargetItem.Result.Geno":
						ultraGridColumn.Width = 50;
						break;
					case "SampleTargetItem.Result.QualityFactor":
						ultraGridColumn.Format = "#,0.00";
						ultraGridColumn.FormatInfo = numberFormatInfo;
						ultraGridColumn.Width = 80;
						break;
					case "WellCell.Well.Result.TypeNo":
					case "WellCell.Well.Result.QualityFactor":
						ultraGridColumn.Format = "#,0.00";
						ultraGridColumn.FormatInfo = numberFormatInfo;
						ultraGridColumn.Width = 80;
						break;
					case "WellCell.Well.Sample.Result.ConclusionList":
					case "WellCell.Well.Result.ConclusionList":
					case "SampleTargetItem.Result.ConclusionList":
						ultraGridColumn.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.FormattedText;
						ultraGridColumn.Width = 120;
						break;
					case "Search.Result.ExperimentName":
					case "Search.Result.ExperimentDate":
					case "Search.Result.SampleName":
						ultraGridColumn.Width = 100;
						break;
					case "Search.Result.FileName":
						ultraGridColumn.Width = 150;
						ultraGridColumn.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.FormattedText;
						break;
					case "WellCell.Well.Sample.PatientInfo.Name":
						ultraGridColumn.Width = 100;
						break;
					case "WellCell.Well.Sample.PatientInfo.Sex":
					case "WellCell.Well.Sample.PatientInfo.Age":
						ultraGridColumn.Width = 40;
						break;
					case "WellCell.Well.Sample.PatientInfo.SpecimenDate":
					case "WellCell.Well.Sample.PatientInfo.Specimen":
						ultraGridColumn.Width = 100;
						break;
					case "WellCell.Well.Sample.PatientInfo.Diagnosis":
					case "WellCell.Well.Sample.PatientInfo.ID":
						ultraGridColumn.Width = 70;
						break;
					case "WellCell.Well.Sample.PatientInfo.Office":
					case "WellCell.Well.Sample.PatientInfo.Doctor":
						ultraGridColumn.Width = 80;
						break;
					}
				}
				ultraGridColumn.Header.Caption = caption;
				ultraGridColumn.Header.VisiblePosition = index;
			}
			ultraGridColumn.Hidden = !visible || IsNullColumn(key);
		}

		private bool IsNumberKey(string key)
		{
			if (!(key == "SampleTargetItem.Result.CnValue"))
			{
				return IsDisplayNumberKey(key);
			}
			return true;
		}

		private bool IsDisplayNumberKey(string key)
		{
			switch (key)
			{
			default:
				if (key.IndexOf("SampleTargetItem.Result.Tm") == -1 && key.IndexOf("SampleTargetItem.Result.Rm") == -1 && !(key == "SampleTargetItem.ChannelNo") && !(key == "SampleTargetItem.Result.QualityFactor"))
				{
					return key == "WellCell.Well.Result.QualityFactor";
				}
				break;
			case "SampleTargetItem.Result.CtValue":
			case "SampleTargetItem.Result.CtMean":
			case "SampleTargetItem.Result.CtSD":
			case "SampleTargetItem.Result.CtCV":
			case "SampleTargetItem.Result.CnSD":
			case "SampleTargetItem.Result.CnMean":
			case "SampleTargetItem.Result.CnCV":
			case "SampleTargetItem.Result.RnValue":
				break;
			}
			return true;
		}

		private bool IsNullColumn(string key)
		{
			bool flag = true;
			return !flag;
		}

		private void informationTable_CellDataRequested(object sender, CellDataRequestedEventArgs e)
		{
			if (e.Row.Index < SearchDatas.Count)
			{
				SearchData searchData = SearchDatas[e.Row.Index];
				e.Data = GetColumnData(e.Column.Key, searchData);
				e.CacheData = false;
			}
		}

		private object GetColumnData(string key, SearchData searchData, bool displayData = true)
		{
			if (key.IndexOf("SampleTargetItem.Result.Tm") == 0)
			{
				int num = Convert.ToInt32(key.Replace("SampleTargetItem.Result.Tm", ""));
				MeltingTargetResult meltingTargetResult = searchData.Item.Result as MeltingTargetResult;
				if (displayData)
				{
					return (meltingTargetResult.PeakValues.Count > num) ? meltingTargetResult.PeakValues[num].Tm : double.NaN;
				}
				if (meltingTargetResult.PeakValues.Count <= num)
				{
					return string.Empty;
				}
				return ResultFormat.Format(meltingTargetResult.PeakValues[num].Tm, "0.00");
			}
			if (key.IndexOf("SampleTargetItem.Result.Rm") == 0)
			{
				int num2 = Convert.ToInt32(key.Replace("SampleTargetItem.Result.Rm", ""));
				MeltingTargetResult meltingTargetResult2 = searchData.Item.Result as MeltingTargetResult;
				if (displayData)
				{
					return (meltingTargetResult2.PeakValues.Count > num2) ? meltingTargetResult2.PeakValues[num2].Rm : double.NaN;
				}
				if (meltingTargetResult2.PeakValues.Count <= num2)
				{
					return string.Empty;
				}
				return ResultFormat.Format(meltingTargetResult2.PeakValues[num2].Rm, "0.00");
			}
			if (key.IndexOf("WellCell.Well.Sample.Result.MidValue") == 0)
			{
				string htKey = key.Replace("WellCell.Well.Sample.Result.MidValue", "");
				MidValue midValue = searchData.Well.Sample.Result.MidValues.Where((MidValue s) => s.Name == htKey).FirstOrDefault();
				if (midValue != null)
				{
					return midValue.Value;
				}
			}
			else if (key.IndexOf("WellCell.Well.Result.MidValue") == 0)
			{
				string htKey2 = key.Replace("WellCell.Well.Result.MidValue", "");
				MidValue midValue2 = searchData.Well.Result.MidValues.Where((MidValue s) => s.Name == htKey2).FirstOrDefault();
				if (midValue2 != null)
				{
					return midValue2.Value;
				}
			}
			else if (key.IndexOf("SampleTargetItem.Result.MidValue") == 0)
			{
				string htKey3 = key.Replace("SampleTargetItem.Result.MidValue", "");
				MidValue midValue3 = searchData.Item.Result.MidValues.Where((MidValue s) => s.Name == htKey3).FirstOrDefault();
				if (midValue3 != null)
				{
					return midValue3.Value;
				}
			}
			else
			{
				switch (key)
				{
				case "WellCell.Well.Sample.PatientInfo.ID":
					return searchData.Well.Sample.PatientInfo.ID;
				case "WellCell.Well.Sample.PatientInfo.Name":
					return searchData.Well.Sample.PatientInfo.Name;
				case "WellCell.Well.Sample.PatientInfo.Sex":
					return searchData.Well.Sample.PatientInfo.Sex;
				case "WellCell.Well.Sample.PatientInfo.Age":
					return searchData.Well.Sample.PatientInfo.Age;
				case "WellCell.Well.Sample.PatientInfo.Specimen":
					return searchData.Well.Sample.PatientInfo.Specimen;
				case "WellCell.Well.Sample.PatientInfo.SpecimenDate":
					return searchData.Well.Sample.PatientInfo.SpecimenDate;
				case "WellCell.Well.Sample.PatientInfo.Doctor":
					return searchData.Well.Sample.PatientInfo.Doctor;
				case "WellCell.Well.Sample.PatientInfo.Office":
					return searchData.Well.Sample.PatientInfo.Office;
				case "WellCell.Well.Sample.PatientInfo.Diagnosis":
					return searchData.Well.Sample.PatientInfo.Diagnosis;
				case "WellCell.Well.Sample.PatientInfo.CaseID":
					return searchData.Well.Sample.PatientInfo.CaseID;
				case "WellCell.Well.Sample.PatientInfo.BedID":
					return searchData.Well.Sample.PatientInfo.BedID;
				case "WellCell.Well.Sample.PatientInfo.InPatientID":
					return searchData.Well.Sample.PatientInfo.InPatientID;
				case "WellCell.Well.Sample.PatientInfo.OutPatientID":
					return searchData.Well.Sample.PatientInfo.OutPatientID;
				case "WellCell.Well.Sample.PatientInfo.Remark":
					return searchData.Well.Sample.PatientInfo.Remark;
				}
				if (key.IndexOf("WellCell.Well.Sample.PatientInfoCustomData.") == 0)
				{
					int num3 = Convert.ToInt32(key.Replace("WellCell.Well.Sample.PatientInfoCustomData.", ""));
					if (num3 < searchData.Well.Sample.PatientInfo.CustomData.Count)
					{
						return searchData.Well.Sample.PatientInfo.CustomData[num3];
					}
				}
				else
				{
					switch (key)
					{
					case "Search.Result.FileName":
						return searchData.FileName;
					case "Search.Result.ExperimentName":
						return Path.GetFileNameWithoutExtension(searchData.FileName);
					case "Search.Result.ExperimentDate":
						return searchData.ExperimentDate.ToLongDateString();
					case "Search.Result.SampleName":
						return searchData.Well.Sample.SampleName;
					}
					switch (key)
					{
					case "WellCell.Well.CellName":
					{
						string text = searchData.Well.CellName;
						if (displayData)
						{
							for (int i = 0; i < 1; i++)
							{
								text = " " + text;
							}
						}
						return text;
					}
					case "WellCell.Well.Project.BasicInfo.Name":
						return searchData.Well.Project.BasicInfo.Name;
					case "WellCell.Well.TubeName":
						return searchData.Item.TubeName;
					case "WellCell.Well.TubeNo":
						return searchData.Item.TubeNo;
					case "SampleTargetItem.ChannelNo":
						return searchData.Item.ChannelNo;
					case "SampleTargetItem.Dye":
						return searchData.Item.Dye;
					case "SampleTargetItem.TargetName":
						return searchData.Item.TargetName;
					case "SampleTargetItem.SampleType":
						return EnumManagement.GetSampleTypeName(searchData.Item.SampleType);
					case "SampleTargetItem.Property":
						if (displayData && searchData.Item.SampleType == SampleType.Standard)
						{
							double result = double.NaN;
							if (double.TryParse(searchData.Item.Property, out result))
							{
								return ResultFormat.Format(result, UseScientific ? "0.000E0" : "#,0.##");
							}
							return searchData.Item.Property;
						}
						return searchData.Item.Property;
					case "WellCell.Well.Sample.CompoundTubeNo":
						return searchData.Well.Sample.CompoundTubeNo;
					case "SampleTargetItem.Result.CtValue":
						if (displayData)
						{
							return searchData.Item.Result.CtValue;
						}
						return ResultFormat.Format(searchData.Item.Result.CtValue, "0.00");
					case "SampleTargetItem.Result.CtMean":
						if (displayData)
						{
							return searchData.Item.Result.CtMean;
						}
						return ResultFormat.Format(searchData.Item.Result.CtMean, "0.00");
					case "SampleTargetItem.Result.CtSD":
						if (displayData)
						{
							return searchData.Item.Result.CtSD;
						}
						return ResultFormat.Format(searchData.Item.Result.CtSD, "0.00");
					case "SampleTargetItem.Result.CtCV":
						if (displayData)
						{
							return searchData.Item.Result.CtCV;
						}
						return ResultFormat.Format(searchData.Item.Result.CtCV, "0.00");
					case "SampleTargetItem.Result.CnValue":
						return ResultFormat.FormatCnValue(searchData.Subset, searchData.Well, searchData.Item.ChannelNo, searchData.Item.Result.CnValue, (!displayData) ? "0.00" : (UseScientific ? "0.000E0" : "#,0.00"));
					case "SampleTargetItem.Result.CnMean":
						if (displayData)
						{
							return searchData.Item.Result.CnMean;
						}
						return ResultFormat.Format(searchData.Item.Result.CnMean, "0.00");
					case "SampleTargetItem.Result.CnSD":
						if (displayData)
						{
							return searchData.Item.Result.CnSD;
						}
						return ResultFormat.Format(searchData.Item.Result.CnSD, "0.00");
					case "SampleTargetItem.Result.CnCV":
						if (displayData)
						{
							return searchData.Item.Result.CnCV;
						}
						return ResultFormat.Format(searchData.Item.Result.CnCV, "0.00");
					case "SampleTargetItem.Result.RnValue":
						if (displayData)
						{
							return searchData.Item.Result.RnValue;
						}
						return ResultFormat.Format(searchData.Item.Result.RnValue, "0.000");
					case "SampleTargetItem.Result.Geno":
					{
						Subset.SubsetParamter subsetParamter = searchData.Subset.GetSubsetParamter(searchData.Well.Project);
						if (subsetParamter == null)
						{
							break;
						}
						HRMOptionItem hRMOptionItem = subsetParamter.BasicOption.Items.Where((BasicOptionItem s) => s.TargetName == searchData.Item.TargetName).FirstOrDefault() as HRMOptionItem;
						if (hRMOptionItem == null)
						{
							break;
						}
						if (hRMOptionItem.TypeMethod == EHRMTypeMethod.Auto)
						{
							return searchData.Subset.GenoTypeList.Where((KeyValuePair s) => (EGenoType)s.Key == ((HRMTargetResult)searchData.Item.Result).GenoType).FirstOrDefault().Value;
						}
						return ((HRMTargetResult)searchData.Item.Result).GenoName;
					}
					case "SampleTargetItem.Result.QualityFactor":
						if (displayData)
						{
							return ((MeltingTargetResult)searchData.Item.Result).QualityFactor;
						}
						return ResultFormat.Format(((MeltingTargetResult)searchData.Item.Result).QualityFactor, "0.00");
					case "WellCell.Well.Result.TypeNo":
						return ((ADWellResult)searchData.Well.Result).TypeName;
					case "WellCell.Well.Result.QualityFactor":
						if (displayData)
						{
							return ((ADWellResult)searchData.Well.Result).QualityFactor;
						}
						return ResultFormat.Format(((ADWellResult)searchData.Well.Result).QualityFactor, "0.00");
					case "WellCell.Well.Sample.Result.ConclusionList":
					{
						StringBuilder stringBuilder = new StringBuilder();
						foreach (Conclusion conclusion in searchData.Well.Sample.Result.ConclusionList)
						{
							stringBuilder.Append(displayData ? ConvertConclusionToHtml(conclusion) : (conclusion.Content + " "));
						}
						return stringBuilder.ToString();
					}
					case "WellCell.Well.Result.ConclusionList":
					{
						StringBuilder stringBuilder = new StringBuilder();
						foreach (Conclusion conclusion2 in searchData.Well.Result.ConclusionList)
						{
							stringBuilder.Append(displayData ? ConvertConclusionToHtml(conclusion2) : (conclusion2.Content + " "));
						}
						return stringBuilder.ToString();
					}
					case "SampleTargetItem.Result.ConclusionList":
					{
						StringBuilder stringBuilder = new StringBuilder();
						foreach (Conclusion conclusion3 in searchData.Item.Result.ConclusionList)
						{
							stringBuilder.Append(displayData ? ConvertConclusionToHtml(conclusion3) : (conclusion3.Content + " "));
						}
						return stringBuilder.ToString();
					}
					}
				}
			}
			return string.Empty;
		}

		private string ConvertConclusionToHtml(Conclusion conclusion)
		{
			return string.Format("<span style=\"color: {0};\">{1}</span> ", conclusion.Color.ToString(), conclusion.Content);
		}

		private void InitUltraGrid()
		{
			numberFormatInfo = CultureInfo.CurrentUICulture.NumberFormat.Clone() as NumberFormatInfo;
			numberFormatInfo.PositiveInfinitySymbol = Utility.GetMessage("NoCt");
			numberFormatInfo.NaNSymbol = string.Empty;
			Infragistics.Win.Appearance appearance = new Infragistics.Win.Appearance();
			Infragistics.Win.Appearance appearance2 = new Infragistics.Win.Appearance();
			Infragistics.Win.Appearance appearance3 = new Infragistics.Win.Appearance();
			Infragistics.Win.Appearance appearance4 = new Infragistics.Win.Appearance();
			Infragistics.Win.Appearance appearance5 = new Infragistics.Win.Appearance();
			Infragistics.Win.Appearance appearance6 = new Infragistics.Win.Appearance();
			Infragistics.Win.Appearance appearance7 = new Infragistics.Win.Appearance();
			Infragistics.Win.Appearance appearance8 = new Infragistics.Win.Appearance();
			Infragistics.Win.Appearance appearance9 = new Infragistics.Win.Appearance();
			Infragistics.Win.Appearance appearance10 = new Infragistics.Win.Appearance();
			Infragistics.Win.Appearance appearance11 = new Infragistics.Win.Appearance();
			Infragistics.Win.Appearance appearance12 = new Infragistics.Win.Appearance();
			ultraGrid.MouseUp += ultraGrid_MouseUp;
			((ISupportInitialize)ultraGrid).BeginInit();
			appearance.BackColor = System.Drawing.SystemColors.Window;
			appearance.BorderColor = System.Drawing.SystemColors.InactiveCaption;
			ultraGrid.DisplayLayout.Appearance = appearance;
			ultraGrid.DisplayLayout.BorderStyle = UIElementBorderStyle.Solid;
			ultraGrid.DisplayLayout.CaptionVisible = DefaultableBoolean.False;
			appearance2.BackColor = System.Drawing.SystemColors.ActiveBorder;
			appearance2.BackColor2 = System.Drawing.SystemColors.ControlDark;
			appearance2.BackGradientStyle = GradientStyle.Vertical;
			appearance2.BorderColor = System.Drawing.SystemColors.Window;
			ultraGrid.DisplayLayout.GroupByBox.Appearance = appearance2;
			appearance3.ForeColor = System.Drawing.SystemColors.GrayText;
			ultraGrid.DisplayLayout.GroupByBox.BandLabelAppearance = appearance3;
			ultraGrid.DisplayLayout.GroupByBox.BorderStyle = UIElementBorderStyle.Solid;
			appearance4.BackColor = System.Drawing.SystemColors.ControlLightLight;
			appearance4.BackColor2 = System.Drawing.SystemColors.Control;
			appearance4.BackGradientStyle = GradientStyle.Horizontal;
			appearance4.ForeColor = System.Drawing.SystemColors.GrayText;
			ultraGrid.DisplayLayout.GroupByBox.PromptAppearance = appearance4;
			ultraGrid.DisplayLayout.MaxColScrollRegions = 1;
			ultraGrid.DisplayLayout.MaxRowScrollRegions = 1;
			appearance5.BackColor = System.Drawing.SystemColors.Window;
			appearance5.ForeColor = System.Drawing.SystemColors.ControlText;
			ultraGrid.DisplayLayout.Override.ActiveCellAppearance = appearance5;
			appearance6.BackColor = System.Drawing.SystemColors.Highlight;
			appearance6.ForeColor = System.Drawing.SystemColors.HighlightText;
			ultraGrid.DisplayLayout.Override.ActiveRowAppearance = appearance6;
			ultraGrid.DisplayLayout.Override.BorderStyleCell = UIElementBorderStyle.Dotted;
			ultraGrid.DisplayLayout.Override.BorderStyleRow = UIElementBorderStyle.Dotted;
			appearance7.BackColor = System.Drawing.SystemColors.Window;
			ultraGrid.DisplayLayout.Override.CardAreaAppearance = appearance7;
			appearance8.BorderColor = Color.Silver;
			appearance8.TextTrimming = Infragistics.Win.TextTrimming.EllipsisCharacter;
			ultraGrid.DisplayLayout.Override.CellAppearance = appearance8;
			ultraGrid.DisplayLayout.Override.CellClickAction = CellClickAction.EditAndSelectText;
			ultraGrid.DisplayLayout.Override.CellPadding = 0;
			appearance9.BackColor = System.Drawing.SystemColors.Control;
			appearance9.BackColor2 = System.Drawing.SystemColors.ControlDark;
			appearance9.BackGradientAlignment = GradientAlignment.Element;
			appearance9.BackGradientStyle = GradientStyle.Horizontal;
			appearance9.BorderColor = System.Drawing.SystemColors.Window;
			ultraGrid.DisplayLayout.Override.GroupByRowAppearance = appearance9;
			appearance10.TextHAlignAsString = "Left";
			ultraGrid.DisplayLayout.Override.HeaderAppearance = appearance10;
			ultraGrid.DisplayLayout.Override.HeaderClickAction = HeaderClickAction.Select;
			ultraGrid.DisplayLayout.Override.HeaderStyle = HeaderStyle.WindowsXPCommand;
			appearance11.BackColor = System.Drawing.SystemColors.Window;
			appearance11.BorderColor = Color.Silver;
			ultraGrid.DisplayLayout.Override.RowAppearance = appearance11;
			ultraGrid.DisplayLayout.Override.RowSelectors = DefaultableBoolean.False;
			appearance12.BackColor = System.Drawing.SystemColors.ControlLight;
			ultraGrid.DisplayLayout.Override.TemplateAddRowAppearance = appearance12;
			ultraGrid.DisplayLayout.ScrollBounds = ScrollBounds.ScrollToFill;
			ultraGrid.DisplayLayout.ScrollStyle = ScrollStyle.Immediate;
			ultraGrid.DisplayLayout.ViewStyleBand = ViewStyleBand.OutlookGroupBy;
			ultraGrid.Name = "ultraGrid";
			ultraGrid.Dock = DockStyle.Fill;
			ultraGrid.TabIndex = 0;
			ultraGrid.Text = "ultraGrid1";
			ultraGrid.DisplayLayout.BorderStyle = UIElementBorderStyle.None;
			ultraGrid.DisplayLayout.GroupByBox.Hidden = true;
			informationTable.ReadOnly = true;
			ultraGrid.DisplayLayout.LoadStyle = LoadStyle.LoadOnDemand;
			ultraGrid.DataSource = informationTable;
			informationTable.CellDataRequested += informationTable_CellDataRequested;
			ultraGrid.InitializeLayout += ultraGrid_InitializeLayout;
			((ISupportInitialize)ultraGrid).EndInit();
			InitMenu();
			windowsFormsHost.Child = ultraGrid;
		}

		private void ultraGrid_InitializeLayout(object sender, InitializeLayoutEventArgs e)
		{
			e.Layout.Override.CellPadding = 2;
			ultraGrid.DisplayLayout.UseFixedHeaders = true;
			e.Layout.Override.DefaultRowHeight = 20;
			e.Layout.Override.FixedHeaderIndicator = FixedHeaderIndicator.None;
			e.Layout.Override.HeaderAppearance.TextHAlign = HAlign.Center;
			e.Layout.Override.HeaderAppearance.TextVAlign = VAlign.Middle;
			e.Layout.Override.HeaderAppearance.BackColor = Utility.GetDrawingColor("ColorDataGridHeadDown");
			e.Layout.Override.HeaderAppearance.BackColor2 = Utility.GetDrawingColor("ColorDataGridHeadUp");
			e.Layout.Override.HeaderAppearance.BackGradientStyle = GradientStyle.Vertical;
			e.Layout.Override.CellAppearance.TextHAlign = HAlign.Center;
			e.Layout.Override.CellAppearance.TextVAlign = VAlign.Top;
			ultraGrid.DisplayLayout.Override.CellClickAction = CellClickAction.RowSelect;
			e.Layout.Override.MergedCellAppearance.TextHAlign = HAlign.Center;
			e.Layout.Override.MergedCellAppearance.TextVAlign = VAlign.Top;
			e.Layout.Override.RowSelectors = DefaultableBoolean.True;
			e.Layout.Override.RowSelectorNumberStyle = RowSelectorNumberStyle.VisibleIndex;
			e.Layout.Override.RowSelectorAppearance.TextHAlign = HAlign.Center;
			e.Layout.Override.RowSelectorAppearance.TextVAlign = VAlign.Middle;
			e.Layout.Override.RowSelectorHeaderStyle = RowSelectorHeaderStyle.SeparateElement;
			e.Layout.Override.RowSelectorAppearance.BackColor = Utility.GetDrawingColor("ColorWellPlateLeft");
			e.Layout.Override.RowSelectorAppearance.BackGradientStyle = GradientStyle.None;
			e.Layout.Override.CellAppearance.TextTrimming = Infragistics.Win.TextTrimming.None;
			e.Layout.Override.SelectedRowAppearance.BackColor = Utility.GetDrawingColor("ColorDataGridCellSelect");
			e.Layout.Override.SelectedRowAppearance.ForeColor = Color.Black;
			e.Layout.Override.ActiveRowAppearance = null;
			e.Layout.Override.RowSizing = RowSizing.Fixed;
			e.Layout.Override.HeaderClickAction = HeaderClickAction.Select;
			e.Layout.ScrollBounds = ScrollBounds.ScrollToFill;
			e.Layout.ScrollStyle = ScrollStyle.Immediate;
		}

		public List<List<string>> GetData(List<SearchData> datas, bool allData = false, bool includeMergerCellInfo = false)
		{
			List<List<string>> list = new List<List<string>>();
			List<KeyValuePair> columnHeader = GetColumnHeader(allData);
			list.Add(columnHeader.Select((KeyValuePair s) => s.Value.ToString()).ToList());
			List<string> list2 = new List<string>();
			foreach (KeyValuePair item in columnHeader)
			{
				KeyValuePair keyValuePair = item;
				list2.Add(string.Empty);
			}
			list.Insert(0, list2);
			List<SearchData> list3 = SearchDatas.ToList();
			if (datas != null)
			{
				list3 = datas;
			}
			for (int i = 0; i < list3.Count; i++)
			{
				SearchData searchData = list3[i];
				SampleTargetItem item2 = searchData.Item;
				List<string> list4 = new List<string>();
				for (int j = 0; j < columnHeader.Count; j++)
				{
					string key = columnHeader[j].Key.ToString();
					object columnData = GetColumnData(key, searchData, false);
					list4.Add((columnData == null) ? null : columnData.ToString());
				}
				list.Add(list4);
			}
			return list;
		}

		public List<KeyValuePair> GetColumnHeader(bool allData = false)
		{
			List<KeyValuePair> list = new List<KeyValuePair>();
			foreach (UltraGridColumn column in ultraGrid.DisplayLayout.Bands[0].Columns)
			{
				string key = column.Key;
				if (allData)
				{
					if (key.IndexOf("SampleTargetItem.Result.Tm") == 0 || key.IndexOf("SampleTargetItem.Result.Rm") == 0 || key.IndexOf("WellCell.Well.Sample.Result.MidValue") == 0 || key.IndexOf("WellCell.Well.Result.MidValue") == 0 || key.IndexOf("SampleTargetItem.Result.MidValue") == 0)
					{
						continue;
					}
					if (key.IndexOf("WellCell.Well.Sample.Result.ConclusionList") == 0)
					{
						int tmCount = GetTmCount();
						for (int i = 0; i < tmCount; i++)
						{
							list.Add(new KeyValuePair
							{
								Value = Utility.GetMessage("Tm") + (i + 1),
								Key = "SampleTargetItem.Result.Tm" + i
							});
							list.Add(new KeyValuePair
							{
								Value = Utility.GetMessage("Rm") + (i + 1),
								Key = "SampleTargetItem.Result.Rm" + i
							});
						}
						List<KeyValuePair> midValue = GetMidValue();
						foreach (KeyValuePair item in midValue)
						{
							list.Add(item);
						}
					}
					if (key.IndexOf("WellCell.Well.TubeName") == 0)
					{
						list.Add(new KeyValuePair
						{
							Value = Utility.GetMessage("tube_no"),
							Key = "WellCell.Well.TubeNo"
						});
					}
				}
				else if (column.Hidden)
				{
					continue;
				}
				list.Add(new KeyValuePair
				{
					Value = column.Header.Caption,
					Key = key
				});
			}
			return list;
		}

		private void ultraGrid_MouseUp(object sender, MouseEventArgs e)
		{
			if (e.Button == MouseButtons.Right)
			{
				((System.Windows.Controls.MenuItem)contextMenu.Items[0]).IsEnabled = ultraGrid.Selected.Cells.Count > 0 || ultraGrid.Selected.Columns.Count > 0 || ultraGrid.Selected.Rows.Count > 0;
				contextMenu.Placement = PlacementMode.MousePoint;
				contextMenu.IsOpen = true;
			}
		}

		private void InitMenu()
		{
			System.Windows.Controls.MenuItem menuItem = null;
			menuItem = new System.Windows.Controls.MenuItem();
			menuItem.Header = Utility.GetMessage("experiment_open");
			menuItem.Click += itemOpenFile_Click;
			contextMenu.Items.Add(menuItem);
			contextMenu.Opened += contextMenu_Opened;
		}

		private void contextMenu_Opened(object sender, RoutedEventArgs e)
		{
			System.Windows.Controls.MenuItem menuItem = (from s in contextMenu.Items.OfType<System.Windows.Controls.MenuItem>()
				where s.Header.Equals(Utility.GetMessage("experiment_open"))
				select s).FirstOrDefault();
			if (menuItem != null)
			{
				menuItem.IsEnabled = ultraGrid.Selected.Rows.Count == 1 || ultraGrid.Selected.Cells.Count == 1;
			}
		}

		private void itemOpenFile_Click(object sender, RoutedEventArgs e)
		{
			int num = -1;
			if (ultraGrid.Selected.Rows.Count == 1)
			{
				num = ultraGrid.Selected.Rows[0].ListIndex;
			}
			else if (ultraGrid.Selected.Cells.Count == 1)
			{
				num = ultraGrid.Selected.Cells[0].Row.ListIndex;
			}
			if (num >= 0 && num < SearchDatas.Count)
			{
				string fileName = SearchDatas[num].FileName;
				RoutedEventArgs routedEventArgs = new RoutedEventArgs();
				routedEventArgs.RoutedEvent = OnSearchExperimentOpenChangedRoutedEvent;
				routedEventArgs.Source = fileName;
				RoutedEventArgs e2 = routedEventArgs;
				RaiseEvent(e2);
			}
		}

		public List<SearchData> GetSelectedData()
		{
			List<UltraGridRow> source = (from UltraGridRow s in ultraGrid.Selected.Rows
				where s.Selected
				select s).ToList();
			List<int> selectIndex = source.Select((UltraGridRow s) => s.ListIndex).Distinct().ToList();
			return SearchDatas.Where((SearchData s) => selectIndex.Contains(SearchDatas.IndexOf(s))).ToList();
		}
	}
}
